package com.feicheng.controller.system;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.feicheng.common.exception.SystemException;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Sample;
import com.feicheng.service.IFRecordService;
import com.feicheng.service.IFSampleService;
import com.feicheng.persistence.model.SamplePagePojo;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangqinglin
 * @since 2022-02-19
 */
@RestController
@RequestMapping("/admin/sample")
public class SampleContronller {

	@Autowired
	IFRecordService IFRecordService;
	
	@Autowired
	IFRecordService recordServiec;
	
	@Autowired
	IFSampleService sampleService;
	
	//案例详情查询接口
	@GetMapping("/sample/info")
	public ResultInfo getSampleInfo (Integer sampleId) {
		if(null == sampleId) {
			throw new SystemException("案例主键缺失");
		}
		
		return sampleService.getSampleInfo(sampleId);
	}
	
	@GetMapping("/sample/page")
	public ResultInfo getSampleByPage( //用于分页查询
			Sample sample,
			@RequestParam(defaultValue="1") Integer current, 
			@RequestParam(defaultValue="10")Integer size) {
		return sampleService.getSamplesByPage(sample,current,size);
	}
	
	
	@PutMapping("/sample/change")
	public ResultInfo updateSample(Sample sample,String url,Boolean imgStatu,Boolean ImgDflg) { //用于 更改
		if (sample.getSampleId() == null) {
			throw new SystemException("丢失主键");
		}
		if (sample.getTitle() == null) {
			throw new SystemException("丢失标题");
		}
		return ResultInfo.success(sampleService.updateSample(sample,url,imgStatu,ImgDflg));
	}
	
	
	
	@PostMapping("/sample/more")
	public ResultInfo insertSample(Sample sample,String url,Boolean imgStatu,Boolean ImgDflg) {
		
		if (sample.getTitle() == null) {
			throw new SystemException("丢失标题");
		}
		if (url == null) {
			throw new SystemException("图片丢失");
		}
		return sampleService.insertSample(sample,url,imgStatu,ImgDflg);
	}
	
	//删除施工案例信息
	@DeleteMapping("/category/deletion")
	public ResultInfo deleteSampleInfo(Integer sampleId) {
		
		if(null == sampleId){
            throw new SystemException("产品ID缺失");
        }
		
		return sampleService.deleteSampleInfo(sampleId);
	}
	
}
